<?php
error_reporting(0);
$isadmin=1; 
include_once '../../comm/config.php';
include_once '../include/page.class.php';
include_once '../../comm/checkpostandget.php';
if(isset($_GET['changesubmit'])){
	$sqlChangeUpdate = "update ".$BIAOTOU."shoplevel set `name`='{$_GET['name']}',`rate`='{$_GET['rate']}',`money`='{$_GET['money']}',`max_money`='{$_GET['max_money']}',`freeflow`='{$_GET['freeflow']}',`expiredate`='{$_GET['expiredate']}' where `id`='{$_GET['id']}'";
	mysql_query($sqlChangeUpdate);
}
if(isset($_GET['addsubmit'])){
	$rate = $_GET['rate']/100;
	$sqlAddInsert = "INSERT into ".$BIAOTOU."shoplevel (`name`,`rate`,`money`,`max_money`,`freeflow`,`expiredate`,`default`) values ('{$_GET['name']}','{$_GET['money']}','{$rate}','{$_GET['max_money']}','{$_GET['freeflow']}','{$_GET['expiredate']}','0')";
	mysql_query($sqlAddInsert);
}
if(isset($_GET['levelsubmit'])){
	$sqlLevelUpdate = "update ".$BIAOTOU."shoplevel set `default`='1' where `id`='{$_GET['level']}'";
	mysql_query($sqlLevelUpdate);
	$sqlBeforeLevelUpdate = "update ".$BIAOTOU."shoplevel set `default`='0' where `id`='{$_GET['beforelevel']}'";
	mysql_query($sqlBeforeLevelUpdate);
}
if(isset($_GET['add'])){
	$type = 'add';
}elseif(isset($_GET['change'])){
	$type = 'change';
	$sqlchange="select * from ".$BIAOTOU."shoplevel where `id` = {$_GET['id']}";
	$sqlchangers = mysql_query($sqlchange);
	$changArr = mysql_fetch_array($sqlchangers);
}elseif(isset($_GET['changelevel'])){
	$type = 'changelevel';
}else{
	$type = 'normal';
}
//if($_GET['change']){
	//$type = 'change';
	//$name = urldecode($_GET['username']);
	//$sj = date("Y-m-d H:i:s");
	//$msg_denyshop=str_replace("[why]",$_GET['denyReason'],$msg_denyshop);
	//$insert = "INSERT into ".$BIAOTOU."msg(ddusername,title,content,addtime,senduser) values ('$name','拒绝店铺','".$msg_denyshop."','".$sj."','网站客服')";
	//mysql_query($insert);
//}

//查询总数
$sqlAccount="select * from ".$BIAOTOU."shoplevel";
$rs = mysql_query($sqlAccount);
$AllCount = mysql_num_rows($rs);
//查询默认级别
$sqlDefault="select * from ".$BIAOTOU."shoplevel where `default` = '1'";
$rs1 = mysql_query($sqlDefault);
$defalutArr = mysql_fetch_array($rs1);

$page = !($_GET['page'])?'1':intval($_GET['page']);
$pagesize=5;
$page2=($page-1)*$pagesize;

//用于分页
$sql="select * from ".$BIAOTOU."shoplevel $where limit $page2,$pagesize";
$rs3 = mysql_query($sql);


?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="../js/jquery.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>管理中心</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"></head>

<body topmargin="5" leftmargin="0">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="282" valign="top"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td>
          <table cellspacing="0" width="100%" height="207" style="border:1px  solid #DCEAF7;">
            <tr>
              <td width="350" height="30" bgcolor="E9F2FB" class="bigtext">
              	<strong>&nbsp;<img src="../images/arrow.gif" width="16" height="22" align="absmiddle" />商户级别管理</strong>&nbsp;&nbsp;&nbsp;&nbsp;
              	<?php if($type == 'changelevel'){?>
              	<strong>新商户默认级别：</strong>
              	<div style="float:right">
              		<form action="">
              		<select name="level" >
              			<?php 
	              			while ($row = mysql_fetch_array($rs))
	              			{
	              				if($row['default'] == '1'){
	              					echo "<option value='{$row['id']}' selected>{$row['name']}</option>";
	              				}else{
	              					echo "<option value='{$row['id']}'>{$row['name']}</option>";
	              				}
	              			}
              			?>
              		</select>
              		<input type ="hidden" value="<?php echo $defalutArr['id']?>" name="beforelevel">
              		<input type="submit" value="确定" name="levelsubmit">
              	</form>
              	</div>
              	<?php }else{?>
              		<strong>新商户默认级别：<?php echo $defalutArr['name'];?></strong>
              	<?php }?>
              </td>
              <td width="450" height="30" bgcolor="E9F2FB" class="bigtext"></td> 
	          <form id="form1" name="form1" method="get" action="">
		          <td width="300" align="right" bgcolor="E9F2FB" class="bigtext">
	              	  <label>
		              	<input type="button" name="change" value="修改默认级别" onclick="location.href='level.php?changelevel=yes&id=<?php echo $defalutArr['id']?>'">
		              </label>
		              <label>
		              	<input type="button" name="add" value="添加级别" onclick="location.href='level.php?add=yes'">
		              </label>
	              	共有 <b><?php echo $AllCount;?></b> 条记录&nbsp;&nbsp;
	              </td>
              </form>
            </tr>
            <?php 
            	if($type == 'normal' || $type == 'changelevel'){
            ?>
            <tr>
              <td colspan="3" valign="top"><table width="100%" height="300" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td valign="top"><table width="100%" border=1 cellpadding=0 cellspacing=0 style="border-collapse: collapse" bordercolor="#dddddd">
                    <tr>
                      <td width="4%" height="30" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;序号</strong></td>
                      <td width="" height="30" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;级别名称</strong></td>
                      <td width="20%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>服务费/米</strong></td>
					  <td width="11%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;月免费流量/米</strong></td>
					  <td width="11%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;有效期/月</strong></td>
                      <td width="13%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;会员开通费用/月</strong></td>
                      <td width="12%" align="center" bgcolor="#F2F2F2" class="bigtext"><strong>&nbsp;执行操作</strong></td>
                    </tr>
					<?php
					$i =1;
					while ($row = mysql_fetch_array($rs3))
					{
						echo "<tr>";
                      	echo "<td align=center height=30 class=bigtext>&nbsp;".$i."</td>";
                      	echo "<td align=center height=30 class=bigtext>&nbsp;".$row["name"]."</td>";
                      	$rate = $row["rate"] * 100;
                      	echo "<td align=center height=30 class=bigtext>&nbsp;".$rate."%，最多".$row["max_money"]."</td>";
						echo "<td align=center height=30 class=bigtext>&nbsp;".$row["freeflow"]."</td>";
						echo "<td align=center class=bigtext>&nbsp;".$row["expiredate"]."</td>";
						echo "<td align=center class=bigtext>&nbsp;".$row["money"]."</td>";
						echo "<td align=center align=center class=bigtext><a href=level.php?change=yes&id={$defalutArr['id']} class=link4>修改</a></td>";
						echo "</tr>";
						$i ++;
					}
					?></table>
					<div class="yahoo2" style=" margin-top:30px;"><?php 
				pageft($total,$pagesize,1,1,0,10,$page_url);
				echo $pagenav;?></div>
					</td>
                </tr>
              </table></td>
            </tr>
            <?php 
            	}elseif($type=="change"){
            ?>
            <form action="">
            <input type="hidden" name="id" value="<?php echo $changArr["id"]; ?>">
            	 <tr>
              <td colspan="3" valign="top"><table width="100%" height="300" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td valign="top"><table width="100%" border=1 cellpadding=0 cellspacing=0
style="border-collapse: collapse" bordercolor="#dddddd">
                  	 <tr>
                        <td height="30" align="right" class="bigtext">级别名称：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="name"  value="<?php echo $changArr["name"]; ?>"/>
                        </td>
                      </tr>
                      <tr>
                        <td height="30" align="right" class="bigtext">服务费：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="rate" value="<?php echo $changArr["rate"]; ?>"> &nbsp;%
                        </td>
                        <td height="30" align="right" class="bigtext">最多/封顶服务费：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="max_money" value="<?php echo $changArr["max_money"]; ?>"> &nbsp;米&nbsp;<font color="red">不限最高就写0</font>
                        </td>
                      </tr>
                      <tr>
                        <td height="30" align="right" class="bigtext">会员开通费用：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="money"  value="<?php echo $changArr["money"]; ?>"/>&nbsp;元&nbsp;<font color="red">没有就写0</font>
                        </td>
                      </tr>
                      <tr>
                        <td height="30" align="right" class="bigtext">每月免费流量：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="freeflow"  value="<?php echo $changArr["freeflow"]; ?>"/>&nbsp;米<font color="red">没有流量就写0</font>
                        </td>
                      </tr>
                      <tr>
                        <td height="30" align="right" class="bigtext">会员有效期：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="expiredate"  value="<?php echo $changArr["expiredate"]; ?>"/>&nbsp;月<font color="red">不限就写0</font>
                        </td>
                      </tr>
                      <tr>
                      	<td></td>
	                      <td>
	                      	<input type="submit" name="changesubmit"/>
	                      </td>
                      </tr>
                    </table>
					</td>
                </tr>
              </table></td>
            </tr>
            </form>
            <?php 		
            	}elseif($type=="add"){
            ?>
            <form action="">
            	 <tr>
              <td colspan="3" valign="top"><table width="100%" height="300" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td valign="top"><table width="100%" border=1 cellpadding=0 cellspacing=0
style="border-collapse: collapse" bordercolor="#dddddd">
                  	 <tr>
                        <td height="30" align="right" class="bigtext">级别名称：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="name"  value=""/>
                        </td>
                      </tr>
                      <tr>
                        <td height="30" align="right" class="bigtext">服务费：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="rate" value=""> &nbsp;%
                        </td>
                        <td height="30" align="right" class="bigtext">最多/封顶服务费：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="max_money" value=""> &nbsp;米&nbsp;<font color="red">不限最高就写0</font>
                        </td>
                      </tr>
                      <tr>
                        <td height="30" align="right" class="bigtext">会员开通费用：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="money"  value=""/>&nbsp;元&nbsp;<font color="red">没有就写0</font>
                        </td>
                      </tr>
                      <tr>
                        <td height="30" align="right" class="bigtext">每月免费流量：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="freeflow"  value=""/>&nbsp;米<font color="red">没有流量就写0</font>
                        </td>
                      </tr>
                      <tr>
                        <td height="30" align="right" class="bigtext">会员有效期：</td>
                        <td height="30">&nbsp;
                        	<input type="text" name="expiredate"  value=""/>&nbsp;月<font color="red">不限就写0</font>
                        </td>
                      </tr>
                      <tr>
                      	<td></td>
	                      <td>
	                      	<input type="submit" name="addsubmit"/>
	                      </td>
                      </tr>
                    </table>
					</td>
                </tr>
              </table></td>
            </tr>
            </form>
            <?php 
            	}
            ?>
            
            
          </table></td>
        </tr>
      
    </table></td>
  </tr>
</table>
</body>
</html>
<?php mysql_close($link);?>
